var jdusername = document.querySelector('[name="jdusername"]');
var jdpassword = document.querySelector("[name='jdpassword']");
var jdpwd = document.querySelector("[name='jdpwd']");
var jdemail = document.querySelector("[name='jdemail']");
var jdtel = document.querySelector("[name='jdtel']");
var tishi1 = document.querySelector(".tishi1");
var tishi2 = document.querySelector(".tishi2");
var tishi3 = document.querySelector(".tishi3");
var tishi4 = document.querySelector(".tishi4");
var tishi5 = document.querySelector(".tishi5");
var tishi6 = document.querySelector(".tishi6");
var userTop = document.querySelector(".userTop");
var ck = document.querySelector(".ck");
var btn = document.querySelector(".btn")
jdusername.onfocus = jdusername.onblur = jdusername.onkeyup = function(e){
        var e = e || window.event;
        user(e);
}
function user(e){
        var t;
        if(e){
                t = e.type;
        }
        var v = jdusername.value;
        if(t == "focus"){
                if(v.length==0){
                        tishi1.innerHTML = "使用字母、数字和符号两种以上的组合，4-20个字符";
                        return false;
                }
        }
        if(t == "blur"){
                if(v.length==0){
                        tishi1.innerHTML = "";
                        return false;
                }
        }
        if(t =='keyup'){
        if(v.length==0){
                tishi1.innerHTML = "请输入用户名";
                return false;
        }else{	
                var reg = /^([\u4e00-\u9fa5]|[a-zA-Z0-9_-])+$/;
                if(reg.test(v)){
                        if(v.length<4||v.length>20){
                                tishi1.innerHTML = "长度4-20个字符";
                                return false;
                        }else{
                                tishi1.innerHTML = "用户名输入正确";
                                return true;
                        }
                }else{	
                               tishi1.innerHTML = "格式输入错误";
                                return false;
                }
        }
}
}
         // 密码
         jdpassword.onfocus = jdpassword.onblur = jdpassword.onkeyup = function(e){
                var e = e || window.event
                paword(e);}
	function paword(e){
		var t;
		if(e){
			t = e.type;
		}
		var v = jdpassword.value;
		if(t == "focus"){
			if(v.length==0){
				tishi2.innerHTML = "建议使用字母、数字和符号两种以上的组合，4-20个字符";
				return false;
			}
		}
		if(t == "blur"){
			if(v.length==0){
				tishi2.innerHTML = "";
				return false;
			}
		}
                if(v.length === 0){
                        tishi2.innerHTML = "请输入密码";
                                return false;
                        }else{
                                var reg =/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/
                                if(reg.test(v)){
                                        //输入的字符串长度范条件
                                        if(v.length<4||v.length>20){
                                                tishi2.innerHTML = "长度4-20个字符";
                                                return false;
                                        }else{
                                                tishi2.innerHTML = "密码格式输入正确";
                                                return true;
                                        }
                                }else{		
                                        tishi2.innerHTML = "密码格式输入错误";
                                        return false;
                                }
                }
        }
                  // 确认密码
                  jdpwd.onfocus = jdpwd.onkeyup = jdpwd.onblur = function(e){
                           var e = e || window.event;
                           paswd(e);
                  }
                  function paswd(e){
                           var t;
                           if(e){
                             t = e.type   
                           }
                           var v = jdpwd.value
                           if(t == 'focus'){
                                if(v.length === 0){
                                tishi3.innerHTML = "请再次输入密码"; 
                               return false}
                           }
                           if(t == 'blur'){
                                if(v.length === 0){
                                        tishi3.innerHTML = ""
                                        return false
                                }
                           }
                if(v.length==0){
                        tishi3.innerHTML = "请再次输入密码";
                        return false;
                        }else{
                        if(v == jdpassword.value){
                                tishi3.innerHTML = "两次密码输入一致";
                                return true;
                        }
                        else{   
                         tishi3.innerHTML ="两次密码输入不一致";
                        return false;}
                        }
        }
                         //    邮箱
                        jdemail.onfocus = jdemail.onblur = jdemail.onkeyup = function(e){
                                var e = e || window.event
                                email(e);
                        }
                        function email(e){
                                var t;
                                var v = jdemail.value
                                if(e){
                                        t = e.type;
                                }
                                if(t == "focus"){
                                        if(v.length==0){
                                                tishi4.innerHTML = "请输入邮箱账号";
                                                return false;
                                        }
                                }
                                if(t == "blur"){
                                        if(v.length==0){
                                                tishi4.innerHTML = " ";
                                                return false;
                                        }
                                }
                                if(v.length==0){	
                                        tishi4.innerHTML = "请输入邮箱";
                                        return false;
                                }else{
                                        var reg = /^\w+@\w+(\.\w+)+$/;
                                        if(reg.test(v)){
                                                tishi4.innerHTML = "输入格式正确";
                                                return true;
                                        }else{
                                                tishi4.innerHTML = "格式输入错误";
                                                return false;
                                        }
                                }
                        }
                        jdtel.onfocus = jdtel.onblur = jdtel.onkeyup = function(e){
                                var e = e || window.event;
                                tel(e);
                        }
                        function tel(e){
                                var t;
                                if(e){
                                        t = e.type;
                                }
                                var v = jdtel.value;
                                if(t == "focus"){
                                        if(v.length==0){
                                               tishi5.innerHTML = "请输入手机号";
                                                return false;
                                        }
                                }
                                if(t == "blur"){
                                        if(v.length==0){
                                               tishi5.innerHTML = "";
                                               return false;
                                        }
                                }
                                
                                if(v.length==0){	
                                        tishi5.innerHTML = "请输入手机号";
                                        return false;
                                }else{	
                                        var reg = /^[1-3]\d{10}$/;
                                        if(reg.test(v)){
                                                tishi5.innerHTML = "格式输入正确";
                                                return true;
                                                
                                        }else{
                                                tishi5.innerHTML = "格式输入错误";
                                                return false;
                                        }
                                }
                        }

btn.onclick = function(){
        if(ck.checked){
                if(user()&&paword()&&paswd()&&email()&&tel()){
                       
                }
                else{
                tishi6.innerHTML = "请同意注册协议";
        }
}
}
